home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3234 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  58 lines

  1. Path: spectre.star.harc.edu!diana!jaewan
  2. From: jaewan@diana.harc.edu (Jaewan Kim - ASTRO)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ display ASCII file
  5. Date: 22 Jan 1996 22:46:39 GMT
  6. Organization: Houston
  7. Distribution: world
  8. Message-ID: <4e144f$82t@spectre.star.harc.edu>
  9. References: <4dtsed$309o@useneta1.news.prodigy.com>
  10. NNTP-Posting-Host: diana.tdl.harc.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. << operator in stream library buffers everything before a space, a tab, 
  14. an eol... And advances after discarding the following whitespaces.
  15. To do what you want to do, you need to use getline, or get functions of 
  16. istream class.
  17.  
  18.  
  19. Shane Morrell (WCME76A@prodigy.com) wrote:
  20. : I am dabbling in C++ (see code below) and need a little assistance with 
  21. : reading an ASCII file using the stream functions.  This works like the 
  22. : dos TYPE command well, I want it to anyway. It does fine except it will 
  23. : not recognize the 'whitespace' in the text file.  When it is displayed, 
  24. : everything is crammedtogetherlikethis.  Arrrgh!
  25.  
  26. : Shane  //    shane@prodigy.com
  27. : =========================================
  28.  
  29. : #include<iostream.h>
  30. : #include<fstream.h>
  31.  
  32. : void main(int argc,char* argv[]) {
  33. :     if(argc<2){
  34. :         cout << "\nFilename parameter needed!";
  35. :              << endl;
  36. :     }
  37. :     else{
  38. :         ifstream src(argv[1], ios::nocreate);
  39. :             if(src) {
  40. :                 char c;
  41.  
  42. :                 src >> c;
  43. :                while(!src.eof()) {
  44. :                      cout << c;
  45. :                      src >> c;
  46. :                }
  47. :              
  48. :                src.close();
  49. :           }
  50. :         else{                    cout << argv[1]
  51. :                          << " does not exist" 
  52. :                          << endl;
  53. :         }
  54. :     }
  55. : }
  56.  
  57.  
  58.